package gr.handmademarket.ui.pages;

import static gr.handmademarket.util.CommonStatics.PROFILE_PICS_PATH;
import gr.handmademarket.po.implementations.Seller;
import gr.handmademarket.po.interfaces.Category;
import gr.handmademarket.ui.panels.ProductsInfoPanel;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.image.NonCachingImage;
import org.apache.wicket.request.resource.ContextRelativeResource;

/**
 * page for displaying products of a category.
 */
public class CategoryPage 
extends CommonTemplatePage{

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Creates a new CategoryPage object. 
	 * @param category 
	 *
	 */
	@SuppressWarnings("nls")
	public CategoryPage(Category category){
		super();
		if (category instanceof Seller){
			String path = PROFILE_PICS_PATH + category.getCode() + ".jpg"; 
			ContextRelativeResource resource = new ContextRelativeResource(path);
			NonCachingImage image = new NonCachingImage("creatorImg", resource);
			add(image);
			Seller seller = (Seller) category;
			add(new Label("shortBio", seller.getShortBio()));
			add(new Label("shopNotes", seller.getShopNotes()));
			add(new Label("shopTitle", "The " + seller.getFirstName() + " " + seller.getLastName() + " shop"));
		}else{
			Image image = new Image("creatorImg","");
			image.setVisible(false);
			add(image);
			add(new Label("shortBio", new String("") ).setVisible(false));
			add(new Label("shopNotes", new String("") ).setVisible(false));
			add(new Label("shopTitle", new String("") ).setVisible(false));
		}
		ProductsInfoPanel panel = new ProductsInfoPanel("imagesPanel", category, null);
		add(panel);
	}
	
}
